<template>
    <div>
        <h2>会员等级添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员等级名称</td>
                    <td>
                        <input type="text" v-model="model.LevelName">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-success" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
const route = useRoute();
const router = useRouter();



let model = reactive({
    "LevelName": '',
})

//添加
const ok = () => {
    if (model.LevelName == "") {
        alert('等级名称不能为空');
        return;
    }


    axios({
        url: 'https://localhost:7035/api/ZMemberLevel/MemberLevelAdd',
        method: 'post',
        data: model,
    })

        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert('等级名称已重复');
                return;
            }
            else if (res.data == 1) {
                alert('添加成功');
                router.push('/memberLevelList')
                return;
            }
            else {
                alert('添加失败');

                return;

            }
        })


        .catch((ree) => {
            console.log(ree);
        })






}





</script>

<style scoped></style>